<?php
header("Content-Type: application/json; charset=UTF-8");
require_once 'db.php';

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    $userId = isset($_GET['user_id']) ? (int)$_GET['user_id'] : 0;
    
    if (!$userId) {
        echo json_encode(['status' => 'error', 'message' => '用户ID不能为空']);
        exit;
    }
    
    $sql = "SELECT id, name, phone, email, age, gender, avatar, created_at 
            FROM users 
            WHERE id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("i", $userId);
    $stmt->execute();
    $result = $stmt->get_result();
    
    if ($result->num_rows > 0) {
        $user_info = $result->fetch_assoc();
        // 格式化创建时间
        $user_info['created_at'] = date('Y-m-d H:i', strtotime($user_info['created_at']));
        echo json_encode(['status' => 'success', 'user_info' => $user_info]);
    } else {
        echo json_encode(['status' => 'error', 'message' => '用户不存在']);
    }
} else {
    echo json_encode(['status' => 'error', 'message' => '不支持的请求方法']);
}

$conn->close();
?>